package mededelingen.view;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.JTextField;

import tools.FieldLimit;
import mededelingen.controller.KnoppenController;
import mededelingen.model.Knoppenlijst;

public class KnoppenView extends JFrame {

	private static KnoppenView instance;

	private JLabel lblTitel = new JLabel("Hulpvraagknoppen");

	private JFrame frame = new JFrame();
	private JPanel mainPanel = new JPanel();
	private ButtonGroup bg = new ButtonGroup();

	private JTextField txtBtn1;
	private JTextField txtBtn2;
	private JTextField txtBtn3;
	private JTextField txtBtn4;
	private JTextField txtActionBtn1;
	private JTextField txtActionBtn2;
	private JTextField txtActionBtn3;
	private JTextField txtActionBtn4;

	public static KnoppenView getInstance() {
		if (instance == null) {
			instance = new KnoppenView();
		}
		return instance;
	}

	private KnoppenView() {	
		initGUI();
		loadData();
	}

	private void loadData() {
		//gegevens uit database laden
		Knoppenlijst.getInstance().loadButtons();

		//button1
		String btn1 = Knoppenlijst.getInstance().getMelding().get(0).getNaam();
		String btn1_2 = Knoppenlijst.getInstance().getMelding().get(0).getBeschrijving();
		//button2
		String btn2 = Knoppenlijst.getInstance().getMelding().get(1).getNaam();
		String btn2_2 = Knoppenlijst.getInstance().getMelding().get(1).getBeschrijving();
		//button3
		String btn3 = Knoppenlijst.getInstance().getMelding().get(2).getNaam();
		String btn3_2 = Knoppenlijst.getInstance().getMelding().get(2).getBeschrijving();
		//button4
		String btn4 = Knoppenlijst.getInstance().getMelding().get(3).getNaam();
		String btn4_2 = Knoppenlijst.getInstance().getMelding().get(3).getBeschrijving();

		//knoppen afkorting
		txtBtn1.setText(btn1);
		txtBtn2.setText(btn2);
		txtBtn3.setText(btn3);
		txtBtn4.setText(btn4);

		//knoppen actie
		txtActionBtn1.setText(btn1_2);
		txtActionBtn2.setText(btn2_2);
		txtActionBtn3.setText(btn3_2);
		txtActionBtn4.setText(btn4_2);
	}

	public void initGUI() {
		//aanpassingen opslaan
		JButton btnOpslaan = new JButton("Opslaan");
		btnOpslaan.setFont(new Font("Tahoma", Font.BOLD, 11));
		btnOpslaan.addActionListener(new KnoppenController(btnOpslaan));
		btnOpslaan.setBounds(414, 247, 109, 23);
		mainPanel.add(btnOpslaan);

		//scherm afsluiten
		JButton btnAnnuleren = new JButton("Annuleren");
		btnAnnuleren.addActionListener(new KnoppenController(btnAnnuleren));
		btnAnnuleren.setBounds(293, 246, 109, 23);
		mainPanel.add(btnAnnuleren);

		//PANEL SETTINGS
		mainPanel.setLocation(0, 0);
		mainPanel.setLayout(null);
		mainPanel.setSize(new Dimension(560, 344));

		lblTitel.setFont(new Font("Tahoma", Font.BOLD, 20));
		lblTitel.setBounds(10, 27, 201, 25);
		mainPanel.add(lblTitel);

		//LABELS
		JLabel lblBtn1 = new JLabel("Naam");
		lblBtn1.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBtn1.setBounds(10, 86, 73, 14);
		mainPanel.add(lblBtn1);

		JLabel lblBtn2 = new JLabel("Naam");
		lblBtn2.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBtn2.setBounds(10, 176, 46, 14);
		mainPanel.add(lblBtn2);

		JLabel lblBtn3 = new JLabel("Naam");
		lblBtn3.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBtn3.setBounds(288, 83, 73, 14);
		mainPanel.add(lblBtn3);

		JLabel lblBtn4 = new JLabel("Naam");
		lblBtn4.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBtn4.setBounds(288, 173, 46, 14);
		mainPanel.add(lblBtn4);

		JLabel lblBeschrijving1 = new JLabel("Beschrijving");
		lblBeschrijving1.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBeschrijving1.setBounds(10, 112, 73, 14);
		mainPanel.add(lblBeschrijving1);

		JLabel lblBeschrijving2 = new JLabel("Beschrijving");
		lblBeschrijving2.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBeschrijving2.setBounds(10, 202, 73, 14);
		mainPanel.add(lblBeschrijving2);

		JLabel lblBeschrijving3 = new JLabel("Beschrijving");
		lblBeschrijving3.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBeschrijving3.setBounds(288, 109, 73, 14);
		mainPanel.add(lblBeschrijving3);

		JLabel lblBeschrijving4 = new JLabel("Beschrijving");
		lblBeschrijving4.setFont(new Font("Tahoma", Font.PLAIN, 13));
		lblBeschrijving4.setBounds(288, 199, 73, 14);
		mainPanel.add(lblBeschrijving4);

		//FIELDS
		txtBtn1 = new JTextField();
		txtBtn1.setBounds(121, 86, 120, 20);
		txtBtn1.setColumns(10);
		txtBtn1.setDocument(new FieldLimit(3));
		mainPanel.add(txtBtn1);

		txtBtn2 = new JTextField();
		txtBtn2.setBounds(121, 173, 120, 20);
		txtBtn2.setColumns(10);
		txtBtn2.setDocument(new FieldLimit(3));
		mainPanel.add(txtBtn2);

		txtBtn3 = new JTextField();
		txtBtn3.setColumns(10);
		txtBtn3.setBounds(399, 83, 120, 20);
		txtBtn3.setDocument(new FieldLimit(3));
		mainPanel.add(txtBtn3);

		txtBtn4 = new JTextField();
		txtBtn4.setColumns(10);
		txtBtn4.setBounds(399, 170, 120, 20);
		txtBtn4.setDocument(new FieldLimit(3));
		mainPanel.add(txtBtn4);

		txtActionBtn1 = new JTextField();
		txtActionBtn1.setColumns(10);
		txtActionBtn1.setBounds(121, 113, 120, 20);
		txtActionBtn1.setDocument(new FieldLimit(15));
		mainPanel.add(txtActionBtn1);

		txtActionBtn2 = new JTextField();
		txtActionBtn2.setColumns(10);
		txtActionBtn2.setBounds(121, 199, 120, 20);
		txtActionBtn2.setDocument(new FieldLimit(15));
		mainPanel.add(txtActionBtn2);

		txtActionBtn3 = new JTextField();
		txtActionBtn3.setColumns(10);
		txtActionBtn3.setBounds(399, 110, 120, 20);
		txtActionBtn3.setDocument(new FieldLimit(15));
		mainPanel.add(txtActionBtn3);

		txtActionBtn4 = new JTextField();;
		txtActionBtn4.setColumns(10);
		txtActionBtn4.setBounds(399, 196, 120, 20);
		txtActionBtn4.setDocument(new FieldLimit(15));
		mainPanel.add(txtActionBtn4);

		//FRAME SETTINGS
		getContentPane().add(mainPanel);
		getContentPane().setLayout(null);
		setTitle("Hulpvraagknoppen");
		setSize(560, 321);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setVisible(true);
		setResizable(false);

		//center frame
		Dimension center = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(center.width / 2 - this.getSize().width / 2,
				center.height / 2 - this.getSize().height / 2);
	}

	//GETTERS EN SETTERS
	public JTextField getTxtBtn1() {
		return txtBtn1;
	}

	public void setTxtBtn1(JTextField txtBtn1) {
		this.txtBtn1 = txtBtn1;
	}

	public JTextField getTxtBtn3() {
		return txtBtn3;
	}

	public void setTxtBtn3(JTextField txtBtn3) {
		this.txtBtn3 = txtBtn3;
	}

	public JTextField getTxtBtn2() {
		return txtBtn2;
	}

	public void setTxtBtn2(JTextField txtBtn2) {
		this.txtBtn2 = txtBtn2;
	}

	public JTextField getTxtBtn4() {
		return txtBtn4;
	}

	public void setTxtBtn4(JTextField txtBtn4) {
		this.txtBtn4 = txtBtn4;
	}

	public JTextField getTxtActionBtn1() {
		return txtActionBtn1;
	}

	public void setTxtActionBtn1(JTextField txtActionBtn1) {
		this.txtActionBtn1 = txtActionBtn1;
	}

	public JTextField getTxtActionBtn2() {
		return txtActionBtn2;
	}

	public void setTxtActionBtn2(JTextField txtActionBtn2) {
		this.txtActionBtn2 = txtActionBtn2;
	}

	public JTextField getTxtActionBtn3() {
		return txtActionBtn3;
	}

	public void setTxtActionBtn3(JTextField txtActionBtn3) {
		this.txtActionBtn3 = txtActionBtn3;
	}

	public JTextField getTxtActionBtn4() {
		return txtActionBtn4;
	}

	public void setTxtActionBtn4(JTextField txtActionBtn4) {
		this.txtActionBtn4 = txtActionBtn4;
	}

}
